package com.example.mylibrary.base;

import android.app.Application;
import android.content.Context;

import com.blankj.utilcode.util.CrashUtils;
import com.blankj.utilcode.util.DeviceUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.Utils;
import com.example.mylibrary.BuildConfig;
import com.example.mylibrary.db.gen.Constant;
import com.example.mylibrary.di.component.BaseComponent;
import com.example.mylibrary.di.component.DaggerBaseComponent;
import com.example.mylibrary.di.module.ApiModule;
import com.example.mylibrary.di.module.BaseModule;
import com.example.mylibrary.di.module.DBModule;
import com.example.mylibrary.utils.SystemUtil;
import com.gyf.immersionbar.ImmersionBar;
import com.squareup.leakcanary.LeakCanary;

/**
 * @author mark.liu
 *         Created by mark.liu on 2017-5-9.
 */
public class BaseApplication extends Application {
//    private static BaseComponent mBaseComponent;
    private static BaseApplication mApplication;

    @Override
    public void onCreate() {
        super.onCreate();

        mApplication = this;
//        initLeakCanary();
//        initBaseComponent();
        initUtils();
        initNetHead();
    }

//    private void initBaseComponent() {
//        mBaseComponent = DaggerBaseComponent
//                .builder()
//                // 提供application
//                .baseModule(new BaseModule(this))
//                .apiModule(new ApiModule())
//                .dBModule(new DBModule())
//                .build();
//    }

    private void initUtils() {
        // 工具类初始化
        Utils.init(this);
        LogUtils.getConfig()
                .setLog2FileSwitch(true)
                .setLogHeadSwitch(true)
                .setBorderSwitch(false)
                // 日志开关
                .setLogSwitch(BuildConfig.LOG_DEBUG)
                // 设置TAG
                .setGlobalTag("BaseProject");
        // 记录崩溃日志
        CrashUtils.init();
    }

    private void initNetHead() {
//        SPUtils.getInstance().put(Constant.HMD, DeviceUtils.getModel());
//        SPUtils.getInstance().put(Constant.HSZ, "1920*1080");
//        SPUtils.getInstance().put(Constant.HV, BuildConfig.VERSION_NAME);
//        SPUtils.getInstance().put(Constant.HSV, SystemUtil.getSystemVersion());
//        SPUtils.getInstance().put(Constant.HAM, "wifi");
//        SPUtils.getInstance().put(Constant.HLO, "0");
//        SPUtils.getInstance().put(Constant.HLA, "0");
//        SPUtils.getInstance().put(Constant.HM, DeviceUtils.getMacAddress());
//        SPUtils.getInstance().put(Constant.HM, NetWorkUtils.getLocalMacAddress(MyApplication.getContext()));
    }

    private void initLeakCanary() {
        if (LeakCanary.isInAnalyzerProcess(this)) {
            return;
        }
        LeakCanary.install(this);
    }

//    public static BaseComponent getBaseComponent() {
//        return mBaseComponent;
//    }

    /**
     * 返回上下文
     */
    public static Context getContext() {
        return mApplication.getApplicationContext();
    }

    public static BaseApplication getBaseApplication() {
        return mApplication;
    }
}
